package com.aplink.generic.util.convertcount;

import java.util.ArrayList;

import com.aplink.generic.constant.type.ControlType;
import com.aplink.generic.pojo.GenericObject;
import com.aplink.generic.pojo.controlspec.ControlSpec;

public class GenericCounter {

    public static int countSubmitButton(
            final ArrayList<ControlSpec> controlSpecList) {

        int count = 0;

        for (final ControlSpec aControlSpec : controlSpecList) {
            if (ControlType.BUTTON == aControlSpec.getControlType()) {
                count++;
            }
        }

        return count;
    }

    public static String getSumValueFromAnAttribute(
            final ArrayList<GenericObject> genericObjectList,
            final String attributeId) {

        double totalValue = 0;
        for (final GenericObject genericObject : genericObjectList) {
            double value = 0;
            try {
                value = Double.valueOf(genericObject.getValue(attributeId)
                        .toString());
            } catch (final Exception e) {
                value = 0;
            }
            totalValue += value;
        }
        return String.valueOf(totalValue);
    }
}
